home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / mit2mo~1.zoo / src / scanner.l < prev    next >
Encoding:
Lex Description  |  1995-08-14  |  932 b   |  43 lines

  1. %{
  2. #include <ctype.h>
  3. #include "global.h"
  4. #include "y.tab.h"
  5.  
  6. unsigned long line_num = 1;
  7. %}
  8.  
  9. ID    [A-Za-z_\.][A-Za-z0-9_]*(\.?)
  10. NUM    ([0-9]+)|(0x[0-9a-fA-f]+)
  11. WS    [     ][     ]*
  12. ES    \\([abfnrtv'"?\\]|[0-7]{1,3}|x[0-9a-fA-F]+)
  13.  
  14. %%
  15.  
  16. {WS}            ;
  17. "|".*$            ;
  18. ^"#".*$            ;
  19. {NUM}            {
  20.               yylval.num = strtoul(yytext, NULL, 0);
  21.               return NUMBER;
  22.             }
  23. {ID}            {
  24.               int n; char *s; static char buf[80];
  25.  
  26.               n = lookup(yytext, buf);
  27.               if (n == 0) {
  28.                 yylval.str = strdup(yytext);
  29.                 s = yylval.str + yyleng - 1;
  30.                 if (*s == '.') *s = '_';
  31.                 return ID;
  32.               } else {
  33.                 yylval.str = strdup(buf);
  34.                 return n;
  35.               }
  36.             }
  37. [0-9]:            {yylval.str = strdup(yytext); return TMPLABEL;}
  38. [0-9][fb]        {yylval.str = strdup(yytext); return TMPLABELfb;}
  39. \"([^"\n\\]|{ES})*\"    {yylval.str = strdup(yytext); return STRING;}
  40. [-+(),:;@&^!*/%<>#=]    return *yytext;
  41. "\n"            {line_num++; return NL;}
  42. .            yyerror("Illegal character %c", *yytext);
  43.